package edu.hitsz.shoot;

import edu.hitsz.aircraft.AbstractAircraft;
import edu.hitsz.aircraft.HeroAircraft;
import edu.hitsz.bullet.BaseBullet;
import edu.hitsz.bullet.EnemyBullet;
import edu.hitsz.bullet.HeroBullet;

import java.util.LinkedList;
import java.util.List;

public class CircleShoot implements ShootStrategy{
    private AbstractAircraft aircraft;
    private int direction;
    private int shootNum = 20;
    private int power = 30;

    public CircleShoot(AbstractAircraft _aircraft, int _direction)
    {
        this.aircraft = _aircraft;
        direction = _direction;
    }

    @Override
    public List<BaseBullet> shoot() {
        List<BaseBullet> res = new LinkedList<>();
        int x = this.aircraft.getLocationX();
        int y = this.aircraft.getLocationY() + direction*2;
        BaseBullet bullet;
        int speedX = 0;
        int speedY = this.aircraft.getSpeedY() + direction*5;
        for(int i=0; i<shootNum; i++){
            double radians = Math.toRadians(18 * i);
//            System.out.println("cos = " + Math.cos(radians) + '\n');
            int speed_x = (int)(10*Math.cos(radians));
            int speed_y = (int)(10*Math.sin(radians));
            if(this.aircraft instanceof HeroAircraft)
                bullet = new HeroBullet(x, y, speed_x, speed_y, power);
            else
                bullet = new EnemyBullet(x, y, speed_x, speed_y, power);
            res.add(bullet);
        }

        return res;
    }

}
